package com.wangp.mywrite.s_netty.netty.ch3;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.CompositeByteBuf;

import static com.wangp.mywrite.s_netty.netty.ch3.TestByteBuf.log;

/**
 * @author tooStronger
 * @date 2023/3/19
 */
public class TestCompositionByteBuf {

    public static void main(String[] args) {
        ByteBuf byteBuf1 = ByteBufAllocator.DEFAULT.buffer().writeBytes(new byte[]{1, 2, 3, 4, 5});
        ByteBuf byteBuf2 = ByteBufAllocator.DEFAULT.buffer().writeBytes(new byte[]{6, 7, 8, 9, 10});

        // 这样写会内存计算，浪费内存
//        ByteBuf buffer = ByteBufAllocator.DEFAULT.buffer();
//        buffer.writeBytes(byteBuf1).writeBytes(byteBuf2);
//        log(buffer);

        CompositeByteBuf buffer = ByteBufAllocator.DEFAULT.compositeBuffer();
        buffer.addComponents(true, byteBuf1, byteBuf2);
        log(buffer);
    }
}
